package com.ldx.java_chatroom.service;

import com.ldx.java_chatroom.mapper.FriendMapper;
import com.ldx.java_chatroom.model.Friend;
import com.ldx.java_chatroom.model.User;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Slf4j
@Service
public class FriendService {
    @Resource
    FriendMapper mapper;

    public List<Friend> getFriendList(HttpServletRequest req) {
        HttpSession session = req.getSession(false);
        if(session==null){
            log.error("用户session不存在");
            return new ArrayList<>();
        }
        User user = (User) session.getAttribute("User");
        if(user == null){
            log.error("用户不存在");
            return new ArrayList<>();
        }
        return mapper.getFriendList(user.getUserId());
    }
}
